{%extends "base.html"%}
{%block title%}{{course.title}} - {%endblock%}

{%block body%}

<script type="text/javascript">
    YAHOO.namespace("example.container");

    function init() {
        // Define various event handlers for Dialog
        var handleSubmit = function() {
            this.submit();
        };
        var handleCancel = function() {
            this.cancel();
        };
        var handleSuccess = function(o) {
            window.location="/viewCourse/{{course.key.id}}";
        };
        var handleFailure = function(o) {
            alert("Submission failed: " + o.status);
        };

        // Instantiate the Dialog
        YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1", 
                            { width : "30em",
                              fixedcenter : true,
                              visible : false, 
                              constraintoviewport : true,
                              buttons : [ { text:"Add", handler:handleSubmit, isDefault:true }, { text:"Cancel", handler:handleCancel, isDefault:false } ]
                            });

        // Wire up the success and failure handlers
        YAHOO.example.container.dialog1.callback = { success: handleSuccess, failure: handleFailure };

        // Render the Dialog
        YAHOO.example.container.dialog1.render();

        YAHOO.util.Event.addListener("show", "click", YAHOO.example.container.dialog1.show, YAHOO.example.container.dialog1, true);
        YAHOO.util.Event.addListener("hide", "click", YAHOO.example.container.dialog1.hide, YAHOO.example.container.dialog1, true);
    }

    YAHOO.util.Event.onDOMReady(init);
</script>

<h2><a href="{%url view.course.listAll course.semester.key.id%}">{{course.semester.name}}</a> >> {{course.title}} - {{course.deptCode}}:{{course.courseCode}}</h2>
<div>
  <table>
    <tr><th>Hours</th><td>{{course.hours}}</td></tr>
    <tr><th>Points</th><td>{{totalScore|floatformat}} / {{totalPossible|floatformat}}</td></tr>
    <tr>
      <th>% Entered</th>
      <td>
        {{totalCorpus|floatformat}}
        {% ifnotequal totalCorpus 100 %}
          <i><span class="warning">Incomplete Data</span></i>
        {% endifnotequal %}
      </td>
    </tr>
    <tr><th>Class Score</th><td>{{classScore|floatformat}} - {{course.grade}}</td></tr>
  </table>
</div>
<div>
  <h3>Assignments</h3>
  {% if course.assignment_set %}
    <table>
      <tr><th>Title</th><th>Due Date</th><th>Score</th><th>Portion<br>of Score</th><th></th></tr>
    {% for assignment in course.assignment_set %}
      <tr>
        <td><a href="{%url view.assignment.edit assignment.key.id%}">{{assignment.name}}</a></td>
        <td>{{assignment.due|date:"m/d/Y"}}</td>
        <td>{{assignment.score|floatformat}}/{{assignment.possible|floatformat}}</td>
        <td>{{assignment.amountOfCorpus|floatformat}}</td>
        <td><a href="{%url view.assignment.delete assignment.key.id%}">[ x ]</a></td>
      </tr>
    {% endfor %}
    </table>
  {% else %}
    <em>no assignments for this course</em>
  {% endif %}
  <button id="show" class="yui-button-focus">Add Assignment</button>
</div>

{# New assignment dialog section --------------------------------------------- #}
<div id="dialog1">
    <div class="hd">
        Enter Assignment
    </div>
    <div class="bd">
        <form action="/addAssignment" method="post">
          <input type="hidden" name="courseid" value="{{course.key.id}}">
          <table>
          {{form}}
          <tr><td colspan=2><input type="submit"/></td></tr> <!-- todo: for testing only -->
          </table>
        </form>
    </div>
</div>

{%endblock%}
